package com.heima.wemedia;

import com.heima.file.service.FileStorageService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

@SpringBootTest
public class OssDemo {
    @Autowired
    FileStorageService fileStorageService;
    @Value("${file.oss.prefix}")
    String prefix;
    @Value("${file.oss.web-site}")
    String webSite;

    @Test
    public void project() throws FileNotFoundException {
        // 阿里云oss中目录名称
        FileInputStream inputStream = new FileInputStream("D:\\Project\\Saved Pictures\\0003.jpg");
        // 返回值: 文件在OSS中的完整名称
        String store = fileStorageService.store(prefix, "R-C.jpg", inputStream);
        System.out.println(webSite + store);
    }
    @Test
    public void delete() throws FileNotFoundException {
        fileStorageService.delete("material/2022/7/20220704/R-C.jpg");
    }
}
